var prefService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch); 

document.getElementById( 'TargetFinderName' ).value = prefService.getCharPref( 'extensions.Ultima.TargetFinderName' );

document.getElementById( 'TargetFinderRaceHuman'    ).checked = prefService.getBoolPref( 'extensions.Ultima.TargetFinderRaceHuman'     );
document.getElementById( 'TargetFinderRaceDarkElf'  ).checked = prefService.getBoolPref( 'extensions.Ultima.TargetFinderRaceDarkElf'   );
document.getElementById( 'TargetFinderRaceElf'      ).checked = prefService.getBoolPref( 'extensions.Ultima.TargetFinderRaceElf'       );
document.getElementById( 'TargetFinderRaceUndead'   ).checked = prefService.getBoolPref( 'extensions.Ultima.TargetFinderRaceUndead'    );
document.getElementById( 'TargetFinderRaceDwarf'    ).checked = prefService.getBoolPref( 'extensions.Ultima.TargetFinderRaceDwarf'     );
document.getElementById( 'TargetFinderRaceAvian'    ).checked = prefService.getBoolPref( 'extensions.Ultima.TargetFinderRaceAvian'     );
document.getElementById( 'TargetFinderRaceOrc'      ).checked = prefService.getBoolPref( 'extensions.Ultima.TargetFinderRaceOrc'       );
document.getElementById( 'TargetFinderRaceFaery'    ).checked = prefService.getBoolPref( 'extensions.Ultima.TargetFinderRaceFaery'     );
document.getElementById( 'TargetFinderRaceGnome'    ).checked = prefService.getBoolPref( 'extensions.Ultima.TargetFinderRaceGnome'     );
document.getElementById( 'TargetFinderRaceHalfling' ).checked = prefService.getBoolPref( 'extensions.Ultima.TargetFinderRaceHalfling'  );

document.getElementById( 'TargetFinderInWar'        ).checked = prefService.getBoolPref( 'extensions.Ultima.TargetFinderInWar'         );
document.getElementById( 'TargetFinderInProtection' ).checked = prefService.getBoolPref( 'extensions.Ultima.TargetFinderInProtection'  );
document.getElementById( 'TargetFinderSelfKD'       ).checked = prefService.getBoolPref( 'extensions.Ultima.TargetFinderSelfKD'        );
document.getElementById( 'TargetFinderGains'        ).checked = prefService.getBoolPref( 'extensions.Ultima.TargetFinderGains'         );

document.getElementById( 'TargetFinderMinLand' ).value = prefService.getIntPref( 'extensions.Ultima.TargetFinderMinLand' );
document.getElementById( 'TargetFinderMaxLand' ).value = prefService.getIntPref( 'extensions.Ultima.TargetFinderMaxLand' );
document.getElementById( 'TargetFinderMinNetw' ).value = prefService.getIntPref( 'extensions.Ultima.TargetFinderMinNetw' );
document.getElementById( 'TargetFinderMaxNetw' ).value = prefService.getIntPref( 'extensions.Ultima.TargetFinderMaxNetw' );
document.getElementById( 'TargetFinderMinNWPA' ).value = prefService.getIntPref( 'extensions.Ultima.TargetFinderMinNWPA' );
document.getElementById( 'TargetFinderMaxNWPA' ).value = prefService.getIntPref( 'extensions.Ultima.TargetFinderMaxNWPA' );
document.getElementById( 'TargetFinderMinKDNW' ).value = prefService.getIntPref( 'extensions.Ultima.TargetFinderMinKDNW' );
document.getElementById( 'TargetFinderMaxKDNW' ).value = prefService.getIntPref( 'extensions.Ultima.TargetFinderMaxKDNW' );

document.getElementById( 'TargetFinderFromLocationKD' ).value = prefService.getIntPref( 'extensions.Ultima.TargetFinderFromKingdom' );
document.getElementById( 'TargetFinderFromLocationIS' ).value = prefService.getIntPref( 'extensions.Ultima.TargetFinderFromIsland'  );
document.getElementById( 'TargetFinderToLocationKD'   ).value = prefService.getIntPref( 'extensions.Ultima.TargetFinderToKingdom'   );
document.getElementById( 'TargetFinderToLocationIS'   ).value = prefService.getIntPref( 'extensions.Ultima.TargetFinderToIsland'    );

document.getElementById( 'TargetFinderMinHonor' ).value = prefService.getIntPref( 'extensions.Ultima.TargetFinderMinHonor' );
document.getElementById( 'TargetFinderMaxHonor' ).value = prefService.getIntPref( 'extensions.Ultima.TargetFinderMaxHonor' );

function Task_Finder() {

TargetFinderName           = document.getElementById( 'TargetFinderName'         ).value;

TargetFinderRaceHuman      = document.getElementById( 'TargetFinderRaceHuman'    ).checked;
TargetFinderRaceDarkElf    = document.getElementById( 'TargetFinderRaceDarkElf'  ).checked;
TargetFinderRaceElf        = document.getElementById( 'TargetFinderRaceElf'      ).checked;
TargetFinderRaceUndead     = document.getElementById( 'TargetFinderRaceUndead'   ).checked;
TargetFinderRaceDwarf      = document.getElementById( 'TargetFinderRaceDwarf'    ).checked;
TargetFinderRaceAvian      = document.getElementById( 'TargetFinderRaceAvian'    ).checked;
TargetFinderRaceOrc        = document.getElementById( 'TargetFinderRaceOrc'      ).checked;
TargetFinderRaceFaery      = document.getElementById( 'TargetFinderRaceFaery'    ).checked;
TargetFinderRaceGnome      = document.getElementById( 'TargetFinderRaceGnome'    ).checked;
TargetFinderRaceHalfling   = document.getElementById( 'TargetFinderRaceHalfling' ).checked;

TargetFinderInWar          = document.getElementById( 'TargetFinderInWar'        ).checked;
TargetFinderInProtection   = document.getElementById( 'TargetFinderInProtection' ).checked;
TargetFinderSelfKD         = document.getElementById( 'TargetFinderSelfKD'       ).checked;
TargetFinderGains          = document.getElementById( 'TargetFinderGains'        ).checked;

TargetFinderMinLand        = Number( document.getElementById( 'TargetFinderMinLand' ).value );
TargetFinderMaxLand        = Number( document.getElementById( 'TargetFinderMaxLand' ).value );
TargetFinderMinNetw        = Number( document.getElementById( 'TargetFinderMinNetw' ).value );
TargetFinderMaxNetw        = Number( document.getElementById( 'TargetFinderMaxNetw' ).value );
TargetFinderMinNWPA        = Number( document.getElementById( 'TargetFinderMinNWPA' ).value );
TargetFinderMaxNWPA        = Number( document.getElementById( 'TargetFinderMaxNWPA' ).value );
TargetFinderMinKDNW        = Number( document.getElementById( 'TargetFinderMinKDNW' ).value );
TargetFinderMaxKDNW        = Number( document.getElementById( 'TargetFinderMaxKDNW' ).value );

TargetFinderFromLocationKD = Number( document.getElementById( 'TargetFinderFromLocationKD' ).value );
TargetFinderFromLocationIS = Number( document.getElementById( 'TargetFinderFromLocationIS' ).value );
TargetFinderToLocationKD   = Number( document.getElementById( 'TargetFinderToLocationKD'   ).value );
TargetFinderToLocationIS   = Number( document.getElementById( 'TargetFinderToLocationIS'   ).value );

TargetFinderMinHonor = Number( document.getElementById( 'TargetFinderMinHonor' ).value );
TargetFinderMaxHonor = Number( document.getElementById( 'TargetFinderMaxHonor' ).value );

if ( TargetFinderMinLand < 0 ) TargetFinderMinLand = 0;
if ( TargetFinderMaxLand < 0 ) TargetFinderMaxLand = 0;
if ( TargetFinderMinNetw < 0 ) TargetFinderMinNetw = 0;
if ( TargetFinderMaxNetw < 0 ) TargetFinderMaxNetw = 0;
if ( TargetFinderMinNWPA < 0 ) TargetFinderMinNWPA = 0;
if ( TargetFinderMaxNWPA < 0 ) TargetFinderMaxNWPA = 0;
if ( TargetFinderMinKDNW < 0 ) TargetFinderMinKDNW = 0;
if ( TargetFinderMaxKDNW < 0 ) TargetFinderMaxKDNW = 0;

prefService.setCharPref( 'extensions.Ultima.TargetFinderName'          , TargetFinderName           );

prefService.setBoolPref( 'extensions.Ultima.TargetFinderRaceHuman'     , TargetFinderRaceHuman      );
prefService.setBoolPref( 'extensions.Ultima.TargetFinderRaceDarkElf'   , TargetFinderRaceDarkElf    );
prefService.setBoolPref( 'extensions.Ultima.TargetFinderRaceElf'       , TargetFinderRaceElf        );
prefService.setBoolPref( 'extensions.Ultima.TargetFinderRaceUndead'    , TargetFinderRaceUndead     );
prefService.setBoolPref( 'extensions.Ultima.TargetFinderRaceDwarf'     , TargetFinderRaceDwarf      );
prefService.setBoolPref( 'extensions.Ultima.TargetFinderRaceAvian'     , TargetFinderRaceAvian      );
prefService.setBoolPref( 'extensions.Ultima.TargetFinderRaceOrc'       , TargetFinderRaceOrc        );
prefService.setBoolPref( 'extensions.Ultima.TargetFinderRaceFaery'     , TargetFinderRaceFaery      );
prefService.setBoolPref( 'extensions.Ultima.TargetFinderRaceGnome'     , TargetFinderRaceGnome      );
prefService.setBoolPref( 'extensions.Ultima.TargetFinderRaceHalfling'  , TargetFinderRaceHalfling   );

prefService.setBoolPref( 'extensions.Ultima.TargetFinderInWar'         , TargetFinderInWar          );
prefService.setBoolPref( 'extensions.Ultima.TargetFinderInProtection'  , TargetFinderInProtection   );
prefService.setBoolPref( 'extensions.Ultima.TargetFinderSelfKD'        , TargetFinderSelfKD         );
prefService.setBoolPref( 'extensions.Ultima.TargetFinderGains'         , TargetFinderGains          );

prefService.setIntPref( 'extensions.Ultima.TargetFinderMinLand'        , TargetFinderMinLand        );
prefService.setIntPref( 'extensions.Ultima.TargetFinderMaxLand'        , TargetFinderMaxLand        );
prefService.setIntPref( 'extensions.Ultima.TargetFinderMinNetw'        , TargetFinderMinNetw        );
prefService.setIntPref( 'extensions.Ultima.TargetFinderMaxNetw'        , TargetFinderMaxNetw        );
prefService.setIntPref( 'extensions.Ultima.TargetFinderMinNWPA'        , TargetFinderMinNWPA        );
prefService.setIntPref( 'extensions.Ultima.TargetFinderMaxNWPA'        , TargetFinderMaxNWPA        );
prefService.setIntPref( 'extensions.Ultima.TargetFinderMinKDNW'        , TargetFinderMinKDNW        );
prefService.setIntPref( 'extensions.Ultima.TargetFinderMaxKDNW'        , TargetFinderMaxKDNW        );
prefService.setIntPref( 'extensions.Ultima.TargetFinderFromKingdom'    , TargetFinderFromLocationKD );
prefService.setIntPref( 'extensions.Ultima.TargetFinderFromIsland'     , TargetFinderFromLocationIS );
prefService.setIntPref( 'extensions.Ultima.TargetFinderToKingdom'      , TargetFinderToLocationKD   );
prefService.setIntPref( 'extensions.Ultima.TargetFinderToIsland'       , TargetFinderToLocationIS   );

prefService.setIntPref( 'extensions.Ultima.TargetFinderMinHonor'       , TargetFinderMinHonor       );
prefService.setIntPref( 'extensions.Ultima.TargetFinderMaxHonor'       , TargetFinderMaxHonor       );

}

function Task_Manager() {
Task_Finder();
setTimeout("Task_Manager()",1);
}

Task_Manager();

function TargetFinderSearch() {

prefService.setBoolPref( 'extensions.Ultima.TargetFinderEnable' , true );
window.open("http://utopia-game.com/wol/game/kingdom_details","_blank","resizable=yes,scrollbars=yes,status=yes");
self.close();

}

function TargetFinderReset() {

document.getElementById( 'TargetFinderName' ).value = "";

document.getElementById( 'TargetFinderRaceHuman'    ).checked = true;
document.getElementById( 'TargetFinderRaceDarkElf'  ).checked = true;
document.getElementById( 'TargetFinderRaceElf'      ).checked = true;
document.getElementById( 'TargetFinderRaceUndead'   ).checked = true;
document.getElementById( 'TargetFinderRaceDwarf'    ).checked = true;
document.getElementById( 'TargetFinderRaceAvian'    ).checked = true;
document.getElementById( 'TargetFinderRaceOrc'      ).checked = true;
document.getElementById( 'TargetFinderRaceFaery'    ).checked = true;
document.getElementById( 'TargetFinderRaceGnome'    ).checked = true;
document.getElementById( 'TargetFinderRaceHalfling' ).checked = true;

document.getElementById( 'TargetFinderInWar'        ).checked = false;
document.getElementById( 'TargetFinderInProtection' ).checked = false;
document.getElementById( 'TargetFinderSelfKD'       ).checked = true;
document.getElementById( 'TargetFinderGains'        ).checked = true;

document.getElementById( 'TargetFinderMinLand' ).value = 0;
document.getElementById( 'TargetFinderMaxLand' ).value = 0;
document.getElementById( 'TargetFinderMinNetw' ).value = 0;
document.getElementById( 'TargetFinderMaxNetw' ).value = 0;
document.getElementById( 'TargetFinderMinNWPA' ).value = 0;
document.getElementById( 'TargetFinderMaxNWPA' ).value = 0;
document.getElementById( 'TargetFinderMinKDNW' ).value = 0;
document.getElementById( 'TargetFinderMaxKDNW' ).value = 0;

document.getElementById( 'TargetFinderFromLocationKD' ).value = 1;
document.getElementById( 'TargetFinderFromLocationIS' ).value = 1;
document.getElementById( 'TargetFinderToLocationKD'   ).value = 1;
document.getElementById( 'TargetFinderToLocationIS'   ).value = 1;

document.getElementById( 'TargetFinderMinHonor' ).value = 0;
document.getElementById( 'TargetFinderMaxHonor' ).value = 9;

}

function TargetFinderClose() {

self.close();

}